package com.eric.test.string;

import java.util.Arrays;

/**
 * @description: 将字符串中间的空格转成指定字符
 * @author: liuBing
 * @create: 2023-02-08 10:29
 **/
public class SpaceToChar {

    /**
     * 指定字符
     */
    private static final String ss = "--";

    public static void main(String[] args) {
        String result = "0     0.5     阴";
        String a = addSpaceResult(result, true);
        System.out.println(a);
    }

    public static String addSpaceResult(String result, boolean addSpace) {
        if (!addSpace) {
            return result;
        }
        StringBuilder finalStr = new StringBuilder();
        Arrays
                .stream(result.split(" "))
                .filter(x -> !x.equals(""))
                .forEach(s -> finalStr.append(s).append(ss));

        return finalStr.substring(0, finalStr.length() - ss.length());
    }
}
